﻿//**********
//save player, load player, show player
//**********

function savePlayer(player) {
  var playerJson = "player = " + toJson(player);
  createCookie('player', playerJson, 0);
  
  showPlayer(player);
}

function list_tohtml(list) {
  var html = "<ul>";
  for (var property in list) {    
    html += "<li>"
    html += property + ": "
    html += "<em>" + list[property] + "</em></li>";
  }
  return html + '</ul>';
}

function showPlayer(player) {
  var playerString = "<h2>";
  if (player != null && player.name != null) {
    playerString += player.name;
  } 
  playerString += "</h2>";
  playerString += "<h3>vital signs</h3>"; //TODO!
  playerString += list_tohtml(player.vitals);
  playerString += "<h3>stash</h3>"; //TODO!
  playerString += list_tohtml(player.items);
  
  overwriteto('#playerinfo', playerString + "</ul>");
}

function loadPlayer(name) {
  //todo: if name is null, then use 'player'
  return eval(readCookie(name));//'player'));
}